﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FrameworkManapro.BusinessModel;
using FrameworkManapro.Utilities;
using FrameworkManapro.WebUI;


namespace GMAC.ReportingSystem.Business.Components
{
    public class CallReasonComponent : IBusinessComponent<Entities.CallReason>
    {
        private DataAccess.CallReasonDataAccess dac;

        public CallReasonComponent()
        {
            dac = new DataAccess.CallReasonDataAccess();
        }

        #region IBusinessComponent<CallReason> Members

        public int Create(Entities.CallReason entityToCreate)
        {
            if (Validate(entityToCreate))
            {
                var result = dac.Insert(entityToCreate);
                return result;
            }
            return 0;
        }

        public int Delete(Entities.CallReason entityToDelete)
        {
            if (entityToDelete.ID <= 0)
                throw new ArgumentOutOfRangeException("ID", "Value must be greater than zero.");

            return dac.Delete(entityToDelete);
        }

        public int Edit(Entities.CallReason entityToEdit)
        {
            if (entityToEdit.ID <= 0)
                throw new ArgumentOutOfRangeException("ID", "Value must be greater than zero.");

            return Validate(entityToEdit) ? dac.Update(entityToEdit) : 0;
        }

        public Entities.CallReason GetDetails(object entityId)
        {
            return dac.Get(entityId);
        }

        protected bool Validate(Entities.CallReason CallReason)
        {
            if (CallReason == null) throw new ArgumentNullException("CallReason", "The argument cannot be null.");
            if (string.IsNullOrEmpty(CallReason.ID.ToString())) throw new ArgumentNullException("ID", "The argument cannot be null.");
            if (string.IsNullOrEmpty(CallReason.Description.ToString())) throw new ArgumentNullException("Description", "The argument cannot be null.");
            if (string.IsNullOrEmpty(CallReason.Status.ToString())) throw new ArgumentNullException("Status", "The argument cannot be null.");
            if (string.IsNullOrEmpty(CallReason.AccounTypeID.ToString())) throw new ArgumentNullException("AccounTypeID", "The argument cannot be null.");


            return true;
        }

        #endregion


        public Entities.CallReasonCollection GetList()
        {
            return dac.GetList();
        }

        //-----------------------------------------------------------------------------------
        /// <summary>
        /// Ricardo Recaredo (25/03/2011)
        /// </summary>
        /// <param name="accountTypeId">Product Id</param>
        /// <returns>CalllReasons Collection filtered by Product</returns>
        //-----------------------------------------------------------------------------------

        public Entities.CallReasonCollection GetListByProduct(int accountTypeId)
        {
            return dac.GetListByProduct(accountTypeId);
        }

        //-----------------------------------------------------------------------------------

        public Entities.CallReasonCollection Search(string Description, int? ProductType, PagingDetails paging)
        {
            if (Description == null) Description = string.Empty;
            return dac.Search(Description, ProductType, paging);
        }

    }
}
